
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <title>表维护</title>
    <style>
        body {
            background: #F7F7F7;
        }


        /*顶部容器*/

        .tophead {
            height: 32px;
            line-height: 32px;
            border: 1px solid #F7F7F7;
            padding: 0 5px;
            margin: 0 2px;
        }

        .tophead .layui-form-item {
            margin-bottom: 0px!important;
        }

        .tophead .layui-form-label {
            padding: 0;
            line-height: 25px;
            width: auto;
        }

        .tophead .layui-input-block {
            margin-left: 32px;
        }

        .tophead .layui-input,
        .layui-select {
            height: 25px;
        }

        .tophead .layui-form-select dl {
            top: 26px;
            padding: 0;
        }

        .tophead .layui-form-select dl dd,
        .layui-form-select dl dt {
            line-height: 24px;
        }

        .tophead .layui-form-item {
            width: 165px;
        }

        .tophead .layui-form-select .layui-edge {
            border-width: 4px;
        }

        .tophead .search .layui-input-block {
            margin-left: 32px;
        }

        .tophead .layui-input-block {
            min-height: 26px;
        }


        /*按钮组边框*/

        .layui-btn-group .layui-btn-primary:first-child {
            border-left: 1px solid #c9c9c9!important;
        }

        .layui-btn-group .layui-btn {
            border-left: 1px solid rgba(255, 255, 255, .5)!important;
        }


        /*按钮大小*/

        .layui-btn {
            height: 26px;
            line-height: 26px;
            font-size: 11px;
        }


        /*table*/

        .layui-table,
        .layui-table-view {
            margin: 0;
        }

        .layui-table td,
        .layui-table th {
            font-size: 11px!important;
        }
    </style>
</head>
<body>
<div>
    <div class="flex flex-align-center flex-jusity-betreen tophead backgroundf">
        <div class="flex flex-align-center">
            <div class="layui-form flex flex-align-center">
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <select id="selType" lay-filter="selType">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item marginleft10 search">
                    <label class="layui-form-label">查询</label>
                    <div class="layui-input-block">
                        <input type="text" id="searchValue" name="searchValue" placeholder="请输入表代码/表名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button type="button" class="layui-btn layui-btn-sm layui-btn-normal marginleft10" onclick="loadData()">确定</button>
            </div>
        </div>

    </div>
    <div style="padding: 2px;width: 100%;background: #F7F7F7;">
        <div class="backgroundf">
            <table id="mygrid" lay-filter="mygrid"></table>
        </div>
    </div>
</div>
</body>
<script>

    var height = dlCommon.getWinHeight();
    var width=dlCommon.getWinWidth();
    var selTableId="";
var templeid=dlCommon.getUrlParam("pid");
    $(function() {


        initGrid();

        initEvent();

        bindForm();

        loadData();

    })
    //数据表
    function loadData(){

        var data={
            serach:$("#searchValue").val(),
            typeid:$("#selType").val()
        };
        layui.table.reload("mygrid",{
            url:"/DevtModelMetadataTableController/getAll",
            where:data,
            loading:true,
            page: false,
            parseData:function(res){
                return {
                    code:res.code,
                    msg:res.msg,
                    data: res.data
                }
            }
        });

    }


    function bindForm(){
        dlCommon.getJSON("/DevtModelMetadataType/getAll",{},function(res){
            var str='<option value="">全部</option>';
            $(res.data).each(function(i,d){
                str+='<option value="'+d.id+'">'+d.flmc+'</option>';
            })
            $("#selType").html(str);
            layui.form.render();
        });

    }
    //初始化grid
    function initGrid(){
        //第一个实例
        layui.table.render({
            elem: '#mygrid'

            ,height: height-50
            ,size: 'sm' //小尺寸的表格
            ,page: false //开启分页
            ,cols: [
            [ //表头
                {field: 'xh', title: '序号', width:'10%', fixed: 'left'}
                ,{field: 'flmc', title: '分类名', width:'20%'}
                ,{field: 'name', title: '表名', width:'20%',}
                ,{field: 'code', title: '表代码', width:'20%'}
                ,{field: 'bz', title: '备注',},
                { field: 'opear', title: '操作',templet: function(d){
                        var str="";

                        str += '<button type="button" onclick="selectTable(\''+d.id+'\')"  class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn">选择</button>';

                        return str;
                    } }
            ]]
        });


    }
    //初始化事件
    function initEvent(){

        //单击表格
        dlCommon.layerTableOn('mygrid', function(obj){
            selTableId=obj.data.id;
        });
    }
    function selectTable(tableid){
        if(!templeid){
            dlCommon.layerInfo("缺少参数")
            return;
        }
        dlCommon.post("/DevtFormMetadataController/save",{
            templeid:templeid,
            tableid:tableid
        },function(res){
            if(!res.success){
                dlCommon.layerInfo(res.msg);
                return;
            }
            parent.getMetadataList();
            dlCommon.layerConfirm("添加成功,是否继续添加",null,function(){
                dlCommon.closeParentLayer();
            })
        },true)
    }
</script>
</html>
